<template>
  <div class="container">
    <div class="counts w wow animate__fadeIn" id="counts">
      <ul>
        <li v-for="(item, index) in list" :key="index">
          <span :class="`iconfont icon icon-${item.icon}`"></span>
          <div class="number">
            <animate-number
              ref="myNum"
              from="0"
              :to="item.count"
              duration="2000"
              mode="manual"
            ></animate-number>
          </div>
          <p>
            <strong>{{ item.point }}</strong
            >&nbsp; {{ item.text }}
          </p>
        </li>
      </ul>
    </div>
  </div>
</template>

<script>
import { WOW } from "wowjs";

export default {
  data() {
    return {
      list: [
        {
          count: 1234,
          icon: "xiaolian",
          point: "Happy Clients",
          text: "consequuntur quae",
        },
        {
          count: 666,
          icon: "xiangmu",
          point: "Projects",
          text: "adipisci atque cum quia aut",
        },
        {
          count: 888,
          icon: "24gf-headset",
          point: "Hours Of Support",
          text: "aut commodi quaerat",
        },
        {
          count: 233,
          icon: "yonghuqunti",
          point: "Hard Workers",
          text: "rerum asperiores dolor",
        },
      ],
    };
  },
  mounted() {
    this.$nextTick(() => {
      // 在dom渲染完后,再执行动画
      var wow = new WOW({
        boxClass: "wow", ///动画元件css类（默认为wow）
        animateClass: "animate__animated", //动画css类（默认为animated）
        offset: 0, //到元素距离触发动画（当默认为0）
        mobile: true, //在移动设备上触发动画（默认为true）
        live: false, //对异步加载的内容进行操作（默认为true）
        callback: (box) => {
          if (box.id === 'counts') {
            setTimeout(() => {
              this.animateStart();
            }, 500);
          }
        },
      });
      wow.init();
    });
  },
  methods: {
    animateStart() {
      for (let i = 0; i < this.list.length; i++) {
        this.$refs.myNum[i].start();
      }
    },
  },
};
</script>

<style lang="less" scoped>
.container {
  background-color: #f4f9fc;
  .counts {
    ul {
      display: flex;
      padding: 60px 0px 30px 0px;
      box-sizing: border-box;
      li {
        flex: 1;
        margin: 0 12px;
        padding: 30px;
        height: 160px;
        box-sizing: border-box;
        .icon {
          font-size: 50px;
          color: #67b0d1;
          display: inline-block;
        }
        .number {
          font-size: 48px;
          line-height: 40px;
          display: inline-block;
          font-weight: 700;
          color: #2f4d5a;
          margin-left: 10px;
        }
        p {
          margin: 10px 0 0 60px;
          font-family: "Raleway", sans-serif;
          font-size: 14px;
          color: #49788c;
        }
      }
    }
  }
}
</style>